package com.example.larouzey.widgettest201ljy;

import android.content.Intent;
import android.hardware.Camera;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private TextView tv;
    private EditText et;
    private Button bt1,bt2;
    private ImageButton ibtn;
    private ImageView iv;

    private RadioButton rb1,rb2;
    private RadioGroup rg;
    private CheckBox cblan,cbzu,cbyou;
    private Button btgetsex,btgethobby;

    private String strfun="";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init(){
        tv=(TextView)findViewById(R.id.textView);
        et=(EditText)findViewById(R.id.editText);
        bt1=(Button)findViewById(R.id.button);
        bt2=(Button)findViewById(R.id.button2);
        iv=(ImageView) findViewById(R.id.imageView);
        ibtn=(ImageButton)findViewById(R.id.imageButton);

        rb1=(RadioButton)findViewById(R.id.radioButton6);
        rb2=(RadioButton)findViewById(R.id.radioButton7);
        rg =(RadioGroup)findViewById(R.id.RadioGroup);

        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int i) {
                switch (i){
                    case R.id.radioButton6:
                        tv.setText("男");
                        break;
                    case R.id.radioButton7:
                        tv.setText("女");
                        break;
                }
            }
        });

        cblan=(CheckBox)findViewById(R.id.checkBox);

        cblan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    strfun+="篮球";
                }else{
                    strfun=strfun.replace("篮球+ ","");
                }
                tv.setText(strfun);
            }
        });

        cbzu=(CheckBox)findViewById(R.id.checkBox2);

        cbzu.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    strfun+="足球";
                }else{
                    strfun=strfun.replace("足球+ ","");
                }
                tv.setText(strfun);
            }
        });

        cbyou=(CheckBox)findViewById(R.id.checkBox3);

        cbyou.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    strfun+="游泳";
                }else{
                    strfun=strfun.replace("游泳 ","");
                }
                tv.setText(strfun);
            }
        });

        btgetsex=(Button)findViewById(R.id.button6);
        btgethobby=(Button)findViewById(R.id.button7);


        bt1.setOnClickListener(this);
        bt2.setOnClickListener(this);
        ibtn.setOnClickListener(this);

        btgetsex.setOnClickListener(this);
        btgethobby.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.button :
                String str = et.getText().toString();
                tv.setText(str);
                break;
            case R.id.button2:
                iv.setImageResource(R.drawable.aaa);
                break;
            case R.id.imageButton:
                Intent intent=new Intent(MainActivity.this,newActivity.class);
                intent.putExtra("param1",et.getText().toString());
                intent.putExtra("param2",3);
                startActivity(intent);
                break;
            case R.id.button6:
                if(rb1.isChecked()){
                    tv.setText("male");
                }
                if(rb2.isChecked()){
                    tv.setText("famle");
                }
                break;
            case R.id.button7:
                String msg="";
                if(cblan.isChecked()){
                    msg+="篮球";
                }
                if(cbzu.isChecked()){
                    msg+="足球";
                }
                if(cbyou.isChecked()){
                    msg+="游泳";
                }
                tv.setText(msg);
                break;
        }
    }
}








